/**
 * 退出系统时需要清空缓存数据
 */
export function removeStorage(){
  uni.removeStorageSync('token')
}

/**
 * showModel弹窗
 */
export function showModel({title="提示！" ,content, success}){
  uni.showModal({
    title: title,
    content: content,
    showCancel: false,
    success: function (res) {
      success && success()
    }
  });
}


/**
 * 计算经纬度距离,返回单位 /m
 */
export function getDistance(lng1, lat1, lng2, lat2) {
  lat1 = parseFloat(lat1)
  lng1 = parseFloat(lng1)
  lat2 = parseFloat(lat2)
  lng2 = parseFloat(lng2)
  console.log("查看经纬度1",lat1,lng1);
  console.log("查看经纬度2",lat2,lng2);

  var dis = 0;
  var radLat1 = toRadians(lat1);
  var radLat2 = toRadians(lat2);
  var deltaLat = radLat1 - radLat2;
  var deltaLng = toRadians(lng1) - toRadians(lng2);
  var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
  return dis * 6378137;

  function toRadians(d) {
    return d * Math.PI / 180;
  }
}

//手机号脱敏处理
export const formatMobile = (mobile) => {
	if (!mobile) return ''
	const pat = /(\d{3})\d*(\d{4})/;
	return mobile.replace(pat, '$1****$2')
}


/**
 * 姓名脱敏
 * 张三 => *三, 王小明 => 王*明
 */
export const formatNameDst = (value) => {
	if (!value) return ''
	if (value) {
		if(value.length <= 2){
			return "*" + value.substring(1,value.length);
		} else if (value.length===3){
				return value[0] + "*" + value[2];
		}else if(value.length > 3){
				return value.substring(0,1) + "**" + value.substring(3,value.length);
		}
	}
}

